package com.gaoqi.mq.topic;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class TopicConsumer {

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue,
                    exchange = @Exchange(value = "topic",type = "topic"),
                    key = {
                           "#.info" ,"*.*"
                    }
            )
    })
    public void receive1MessageFromTopic(Channel channel, Message message){
        System.out.println("消费线程1消费:"+new String(message.getBody()));
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue,
                    exchange = @Exchange(value = "topic",type = "topic"),
                    key = {
                            "*.admin.#"
                    }
            )
    })
    public void receive2MessageFromTopic(Channel channel, Message message){
        System.out.println("消费线程2消费:"+new String(message.getBody()));
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue,
                    exchange = @Exchange(value = "topic",type = "topic"),
                    key = {
                            "error.info",
                    }
            )
    })
    public void receive3MessageFromTopic(Channel channel, Message message){
        System.out.println("消费线程3消费:"+new String(message.getBody()));
    }
}
